<?php
namespace app\api;
use think\Cache;
use think\Model;
use think\Request;

class BaseModel extends Model
{
    public $request;
    public $requestData;
    protected $user;
    public function __construct($data = [])
    {
        parent::__construct($data);
        $this->request = Request::instance();
        $this->requestData = empty($data)?$this->request->param(''):$data;
        if ($this->request->__get('user')){
            $this->user = $this->request->__get('user');
        }
    }

    /**
     * 检查数据是否为空
     */
    public function checkData($data,$error_msg)
    {
        if(empty($data) || empty($error_msg)) return array('message' => '参数错误');
        foreach($data as $k => $v){
            if(!array_key_exists($v,$this->requestData)) return array('message' => $error_msg[$k]);
        }
        return array();
    }


}